package edu.task.repository;

import edu.task.model.SysMsg;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysMsgRepository extends JpaRepository<SysMsg, Long> {


    @Query(value = "select * from sys_msg as m " +
            "inner join sys_user_msg as um on um.msg_id = m.msg_id " +
            "inner join sys_user as u on um.user_id = u.user_id " +
            "where um.user_id=:userId ", nativeQuery = true)
    List<SysMsg> selectMsgByUserId(Long userId);

    @Modifying
    @Query(value = "delete from sys_msg where msg_id=:msgId",nativeQuery = true)
    int deleteMsgById(Long msgId);
}
